﻿using MM.Common.Base;
using MM.Common.DBBase;
using MM.Common.Setup;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MM.Common.Support
{
    public partial class FrmParameterEmpSetup : FrmSetupWithSelect
    {
        public FrmParameterEmpSetup()
        {
            InitializeComponent();
        }
        protected void DispInfo()
        {
            DataParamCol parm = new DataParamCol(new DataParam[] { new InputDataParam("id", base.mainCode.ToString()) });
            base.RetrieveData(parm);
            base.dtSetup.Columns["PARAMETER_TYPE"].DefaultValue = "C";
            base.dtSetup.Columns["EMP_ID"].DefaultValue = base.mainCode;
        }

        private void FrmSysConfigSetup_Load(object sender, EventArgs e)
        {
            this.gvParameter.Columns["PARAMETER_NAME_CHN"].Tag = "ON";
            this.gvParameter.Columns["DESCRIBE"].Tag = "ON";
            base.gvSetup = this.gvParameter;
            string selsql = "SELECT EMP_ID ,PARAMETER_NAME, PARAMETER_NAME_CHN, PARAMETER_VALUE, PARAMETER_TYPE ,DESCRIBE FROM MXHLY_SYS_PARAMETER_EMP WHERE EMP_ID = :id ORDER BY PARAMETER_NAME ASC ";
            base.setSql(selsql, "MXHLY_SYS_PARAMETER_EMP", new string[] { "EMP_ID", "PARAMETER_NAME" }, null, "", "");
            DataTable table = new DataTable();
            table.Columns.Add("TYPE_CODE", typeof(string));
            table.Columns.Add("TYPE_NAME", typeof(string));
            table.Rows.Add(new object[] { "C", "字符" });
            table.Rows.Add(new object[] { "N", "数字" });
            table.Rows.Add(new object[] { "D", "日期" });
            this.riParameterType.DataSource = table;
            this.riParameterType.DisplayMember = "TYPE_NAME";
            this.riParameterType.ValueMember = "TYPE_CODE";
            base.ZoomWin();
            base.mainCode = SystemInfo.OperId;
            this.DispInfo();
            base.selectFresh();
            base.nbiFresh.Visible = SystemInfo.OperIsAdmin;
        }

        protected override bool selectFresh()
        {
            base.selectFresh();
            if (this.dtEmp == null)
            {
                this.dtEmp = new DataTable();
                SystemInfo.DbData.Retrieve("SELECT EMP_ID ,EMP_CODE ,EMP_NAME FROM MXH_EMPLOYEE ORDER BY EMP_CODE", ref this.dtEmp);
            }
            int[] numArray = new int[3];
            numArray[1] = 30;
            numArray[2] = 60;
            FrmSelectFromGrid grid = new FrmSelectFromGrid(this.dtEmp, new string[] { "标识", "工号", "姓名" }, numArray, "人员选择");
            if (grid.ShowDialog(this) != DialogResult.Cancel)
            {
                int choiceRow = grid.ChoiceRow;
                base.mainCode = this.dtEmp.Rows[choiceRow]["EMP_ID"];
                this.Text = "人员参数设置 --- " + this.dtEmp.Rows[choiceRow]["EMP_NAME"].ToString();
                grid.Dispose();
                this.DispInfo();
                return true;
            }
            base.mainCode = new object();
            return false;
        }
    }
}
